<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h:form id="userForm" enctype="multipart/form-data">
                <br/>
                <h3 class="title">Pesquisando Memorial Descritivo</h3>
                
                <p:growl id="messages" showDetail="true" autoUpdate="true"  /> 
                <div class="row">
                    <div class="twelve columns"> 


                        <p:panel id="intPanel" style="background: none; border: none;" 
                                 styleClass="container_24 clearfix both ">
                            <fieldset>
                                <legend> <h4 style="margin:0 0 10px 0">Interessado</h4></legend>
                                <p:outputLabel value="Pessoa: "  styleClass="grid_3"/>
                                <p:selectOneRadio id="typePerson" style="margin-top:-8px;" styleClass="grid_8"
                                                  value="#{managerSearchDataSheet.searchInterested.typeDocument}" >  
                                    <f:selectItems value="#{managerSearchDataSheet.typeDocumentList()}" />
                                    <p:ajax event="change" update=":userForm:intPanel" 
                                            />
                                </p:selectOneRadio>

                                <div class="clear"/>

                                <p:outputLabel id="typeDocumentLabel" 
                                                value="#{managerSearchDataSheet.searchInterested.typeDocument}: " 
                                                styleClass="grid_3"/>

                                <p:inputMask id="typeDocumentInput" 
                                                value="#{managerSearchDataSheet.searchInterested.typeDocument.type eq 'CPF' ? 
                                                        managerSearchDataSheet.searchInterested.cpf : managerSearchDataSheet.searchInterested.cnpj}"
                                                mask="#{managerSearchDataSheet.searchInterested.typeDocument.type eq 'CPF' ? 
                                                        '999.999.999-99':'99.999.999/9999-99'}" 
                                                styleClass="grid_8" > 

                                </p:inputMask>
                                <div class="clear"/>
                                <p:outputLabel value="Nome: " styleClass="grid_3" for="nomeInputText" 
                                               rendered="#{managerSearchDataSheet.searchInterested.typeDocument.type eq 'CPF'}"/>
                                <p:inputText id="nomeInputText" styleClass="grid_20 ajustInput"  
                                             value="#{managerSearchDataSheet.searchInterested.name}" 
                                             rendered="#{managerSearchDataSheet.searchInterested.typeDocument.type eq 'CPF'}" />

                                <p:outputLabel value="Fantasia: " styleClass="grid_3" for="nameFantasyInputText" 
                                                rendered="#{managerSearchDataSheet.searchInterested.typeDocument.type eq 'CNPJ'}" />
                                <p:inputText id="nameFantasyInputText" styleClass="grid_20 ajustInput"
                                                value="#{managerSearchDataSheet.searchInterested.name_fantasy}" 
                                                rendered="#{managerSearchDataSheet.searchInterested.typeDocument.type eq 'CNPJ'}" />
                            </fieldset>
                        </p:panel>
                        
                        <p:panel id="TransmitentePanel" style="background: none; border: none;" 
                                 styleClass="container_24 clearfix both ">
                            <fieldset>
                                <legend> <h4 style="margin:0 0 10px 0">Transmitente</h4></legend>
                                <p:outputLabel value="Pessoa: "  styleClass="grid_3"/>
                                <p:selectOneRadio id="typePersonTransmitente" styleClass="grid_8"
                                                  value="#{managerSearchDataSheet.searchTransmitente.typeDocument}" >  
                                    <f:selectItems value="#{managerSearchDataSheet.typeDocumentList()}" />
                                    <p:ajax event="change" update=":userForm:TransmitentePanel" 
                                            />
                                </p:selectOneRadio>

                                <div class="clear"/>

                                <p:outputLabel id="typeDocumentLabelTransmitente" 
                                                value="#{managerSearchDataSheet.searchTransmitente.typeDocument}: " 
                                                styleClass="grid_3"/>

                                <p:inputMask id="typeDocumentInputTransmitente" 
                                                value="#{managerSearchDataSheet.searchTransmitente.typeDocument.type eq 'CPF' ? 
                                                        managerSearchDataSheet.searchTransmitente.cpf : managerSearchDataSheet.searchTransmitente.cnpj}"
                                                mask="#{managerSearchDataSheet.searchTransmitente.typeDocument.type eq 'CPF' ? 
                                                        '999.999.999-99':'99.999.999/9999-99'}" 
                                                styleClass="grid_8" > 

                                </p:inputMask>
                                <div class="clear"/>
                                <p:outputLabel value="Nome: " styleClass="grid_3" for="nomeTransInputText" 
                                               rendered="#{managerSearchDataSheet.searchTransmitente.typeDocument.type eq 'CPF'}"/>
                                <p:inputText id="nomeTransInputText" styleClass="grid_20 ajustInput"  
                                             value="#{managerSearchDataSheet.searchTransmitente.name}" 
                                             rendered="#{managerSearchDataSheet.searchTransmitente.typeDocument.type eq 'CPF'}" />

                                <p:outputLabel value="Fantasia: " styleClass="grid_3" for="nameFantasyInputText" 
                                                rendered="#{managerSearchDataSheet.searchTransmitente.typeDocument.type eq 'CNPJ'}" />
                                <p:inputText id="nameFantasyTransInputText" styleClass="grid_20 ajustInput"
                                                value="#{managerSearchDataSheet.searchTransmitente.name_fantasy}" 
                                                rendered="#{managerSearchDataSheet.searchTransmitente.typeDocument.type eq 'CNPJ'}" />
                            </fieldset>
                        </p:panel>
                        
                         <p:panel id="AdquirentePanel" style="background: none; border: none;" 
                                 styleClass="container_24 clearfix both ">
                            <fieldset>
                                <legend> <h4 style="margin:0 0 10px 0">Adquirente</h4></legend>
                                <p:outputLabel value="Pessoa: "  styleClass="grid_3"/>
                                <p:selectOneRadio id="typePersonAdquirente" style="margin-top:-8px;" styleClass="grid_8"
                                                  value="#{managerSearchDataSheet.searchAdquirente.typeDocument}" >  
                                    <f:selectItems value="#{managerSearchDataSheet.typeDocumentList()}" />
                                    <p:ajax event="change" update=":userForm:AdquirentePanel" 
                                            />
                                </p:selectOneRadio>

                                <div class="clear"/>

                                <p:outputLabel id="typeDocumentLabelAdquirente" 
                                                value="#{managerSearchDataSheet.searchAdquirente.typeDocument}: " 
                                                styleClass="grid_3"/>

                                <p:inputMask id="typeDocumentInputAdquirente" 
                                                value="#{managerSearchDataSheet.searchAdquirente.typeDocument.type eq 'CPF' ? 
                                                        managerSearchDataSheet.searchAdquirente.cpf : managerSearchDataSheet.searchAdquirente.cnpj}"
                                                mask="#{managerSearchDataSheet.searchAdquirente.typeDocument.type eq 'CPF' ? 
                                                        '999.999.999-99':'99.999.999/9999-99'}" 
                                                styleClass="grid_8" > 

                                </p:inputMask>
                                <div class="clear"/>
                                <p:outputLabel value="Nome: " styleClass="grid_3" for="nomeAdqInputText" 
                                               rendered="#{managerSearchDataSheet.searchAdquirente.typeDocument.type eq 'CPF'}"/>
                                <p:inputText id="nomeAdqInputText" styleClass="grid_20 ajustInput"
                                             value="#{managerSearchDataSheet.searchAdquirente.name}" 
                                             rendered="#{managerSearchDataSheet.searchAdquirente.typeDocument.type eq 'CPF'}" />

                                <p:outputLabel value="Fantasia: " styleClass="grid_3" for="nameFantasyAdqInputText" 
                                                rendered="#{managerSearchDataSheet.searchAdquirente.typeDocument.type eq 'CNPJ'}" />
                                <p:inputText id="nameFantasyAdqInputText" styleClass="grid_20 ajustInput"
                                                value="#{managerSearchDataSheet.searchAdquirente.name_fantasy}" 
                                                rendered="#{managerSearchDataSheet.searchAdquirente.typeDocument.type eq 'CNPJ'}" />

                            </fieldset>
                        </p:panel>
                        
                        <br/>
                        <div class="buttonAction">
                            <p:commandButton value="Pesquisar" icon="ui-icon-search"
                                             update="@form, tableReq, intPanel"
                                             actionListener="#{managerSearchDataSheet.searchDataSheet()}"
                                             styleClass="ui-priority-primary" />
                            <p:button href="indexdatasheet.xhtml" value="Cancelar"  icon="ui-icon-trash" />
                        </div >
                    </div>
                    <fieldset>
                        <legend> <h4 style="margin:0 0 10px 0">Resultado</h4></legend>
                        <p:panel id="resultPanel" style="background: none; border: none;" 
                                 styleClass="container_24 clearfix ">

                            <p:dataTable id="tableReq" var="r" value="#{managerSearchDataSheet.datasheets}" 
                                         styleClass="grid_24" 
                                         rowIndexVar="rowid"
                                         rowKey="#{r.id}"
                                         rows="5" paginator="true"  
                                         paginatorPosition="bottom"
                                         emptyMessage="Nenhum registro">  
                                <f:facet name="header">
                                    Memorial Descritivo
                                </f:facet>
                                <p:column headerText="Ação" width="20">  
                                    <p:button  style="width: 20px; height: 20px;" 
                                               title="editar"
                                               href="editdatasheet.xhtml?eSheet=#{r.id}"
                                               icon="ui-icon-pencil"/>
                                    <p:button  style="width: 20px; height: 20px;" 
                                               title="visualizar"
                                               href="showdatasheet.xhtml?sSheet=#{r.id}"
                                               icon="ui-icon-zoomin"/>
                                </p:column> 
                                <p:column headerText="Imóvel" width="200">  
                                    <ui:repeat value="#{r.realty.identificationRealty}" var="i">
                                        
                                            <h:outputText value="Uma(a) #{r.realty.typeRealty.name}
                                                          situado na #{i.patio}, bairro #{i.neighborhood}"/>
                                       
                                    </ui:repeat>
                                </p:column>
                                <p:column headerText="Partes" width="200">  
                                    <ui:repeat value="#{r.adquirente}" var="a">
                                        <p:panelGrid columns="1">
                                            <f:facet name="header">
                                                Adquirente
                                            </f:facet>
                                            <h:outputText value="#{a.name}"/>

                                        </p:panelGrid>
                                    </ui:repeat>
                                    <ui:repeat value="#{r.transmitente}" var="t">
                                        <p:panelGrid columns="1">
                                            <f:facet name="header">
                                                Transmitente
                                            </f:facet>
                                            <h:outputText value="#{t.name}" />

                                        </p:panelGrid>
                                    </ui:repeat>
                                </p:column>



                            </p:dataTable> 

                        </p:panel>

                    </fieldset>

                </div>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
